<template>
  <div>
    <div class="return-btn">
      <van-button icon="arrow-left" type="default" to="/home" plain />
    </div>
    <div class="acc-title">账号注册</div>
    <div class="inputting">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="用户名"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit"
            >注册</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
export default {
  name: '',
  data () {
    return {
      username: '',
      password: '',
      checked: true,
    }
  },
  methods: {
    onSubmit (values) {
      console.log('submit', values)
      console.log(this.username)
      const username = this.username
      const password = this.password
      const history = []
      const current = {
        username,
        password,
        history,
      }
      // console.log(this.$store.commit)
      this.$store.commit('addToUse', current)
      // console.log('11' + this.$store.state.log)
      // return this.$store.state.log
      console.log(sessionStorage.getItem('log'))
      if (sessionStorage.getItem('log') === 'true') {
        this.$router.push('/mine')
      }
    },
  },
  computed: {},
  components: {},
  created () {},
}
</script>

<style lang="less" scoped>
.return-btn {
  margin: 20px 0 0 20px;
  .van-button--normal {
    border: none;
    font-size: 30px;
  }
}
.acc-title {
  margin-top: 20px;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 25px;
}
.inputting {
  width: 330px;
  margin: 0px auto;
  .van-button--info {
    background: #42bd56;
    border-color: #42bd56;
  }
}
</style>
